﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RFW.Weather.WeatherFlash
{
	public class WFlash2 : Communication
	{
		private CurrentConditions _currentConditions = null;

        public WFlash2(CurrentConditions currentConditions, string URI) 
            : base(URI, false)
        {
			_currentConditions = currentConditions;
        }

		public override void Process(System.Xml.Linq.XDocument results)
		{
		}

		public override void Process(string results)
		{
			try
			{
				string[] values = results.Split(',');

				_currentConditions.Wind.SpeedHigh = new HighLow
				{
					Value = values[31].ToDecimal(),
					Time = values[59].ToDateTime()
				};

				_currentConditions.Wind.GustHigh = new HighLow
				{
					Value = values[32].ToDecimal(),
					Time = values[60].ToDateTime()
				};

				_currentConditions.InHumidity.High = new HighLow
				{
					Value = values[33].ToDecimal(),
					Time = values[61].ToDateTime()
				};

				_currentConditions.Humidity.High = new HighLow
				{
					Value = values[34].ToDecimal(),
					Time = values[62].ToDateTime()
				};

				_currentConditions.InTemperature.High = new HighLow
				{
					Value = values[35].ToDecimal(),
					Time = values[63].ToDateTime()
				};

				_currentConditions.Temperature.High = new HighLow
				{
					Value = values[36].ToDecimal(),
					Time = values[64].ToDateTime()
				};

				_currentConditions.Barometer.RawHigh = new HighLow
				{
					Value = values[37].ToDecimal(),
					Time = values[65].ToDateTime()
				};

				_currentConditions.Solar.UVIndexHigh = new HighLow
				{
					Value = values[46].ToDecimal(),
					Time = values[76].ToDateTime()
				};

				_currentConditions.Solar.RadiationHigh = new HighLow
				{
					Value = values[47].ToDecimal(),
					Time = values[77].ToDateTime()
				};

				_currentConditions.Temperature.WindChillHigh = new HighLow
				{
					Value = values[48].ToDecimal(),
					Time = values[76].ToDateTime()
				};

				_currentConditions.InTemperature.HeatIndexHigh = new HighLow
				{
					Value = values[49].ToDecimal(),
					Time = values[77].ToDateTime()
				};

				_currentConditions.Temperature.HeatIndexHigh = new HighLow
				{
					Value = values[50].ToDecimal(),
					Time = values[78].ToDateTime()
				};

				_currentConditions.Wind.SpeedLow = new HighLow
				{
					Value = values[87].ToDecimal(),
					Time = values[115].ToDateTime()
				};

				_currentConditions.Wind.GustLow = new HighLow
				{
					Value = values[88].ToDecimal(),
					Time = values[116].ToDateTime()
				};

				_currentConditions.InHumidity.Low = new HighLow
				{
					Value = values[89].ToDecimal(),
					Time = values[117].ToDateTime()
				};

				_currentConditions.Humidity.Low = new HighLow
				{
					Value = values[90].ToDecimal(),
					Time = values[118].ToDateTime()
				};

				_currentConditions.InTemperature.Low = new HighLow
				{
					Value = values[91].ToDecimal(),
					Time = values[119].ToDateTime()
				};

				_currentConditions.Temperature.Low = new HighLow
				{
					Value = values[92].ToDecimal(),
					Time = values[120].ToDateTime()
				};

				_currentConditions.Barometer.RawLow = new HighLow
				{
					Value = values[93].ToDecimal(),
					Time = values[121].ToDateTime()
				};

				_currentConditions.Rain.Daily = values[254].ToDecimal();
				_currentConditions.Rain.Hourly = values[255].ToDecimal();
				_currentConditions.Rain.TwentyFourHour = values[256].ToDecimal();
				_currentConditions.Rain.Rate = values[257].ToDecimal();
				_currentConditions.Rain.Monthly = values[262].ToDecimal();

				_currentConditions.Wind.WindRun = values[258].ToDecimal();
				_currentConditions.Wind.WindRunMonth = values[265].ToDecimal();
				_currentConditions.Wind.WindRunYear = values[268].ToDecimal();

				_currentConditions.Forecast = new Forecast
				{
					HeatStress = values[269].URLDecode(),
					ComformatLevel = values[270].URLDecode(),
					Value = values[271].URLDecode(),
					BarometerTrend = values[272].URLDecode(),
					PressureTrend = values[273].URLDecode(),
					BeaufortScale = values[274].URLDecode()
				};
			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine(ex.Message);
			}
		}


		internal override void Failed()
		{
		}
	}
}
